package com.lagou.oss.controller;

import com.lagou.oss.bean.OSSResult;
import com.lagou.oss.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RequestMapping("/oss")
@RestController
public class OSSController {

    @Autowired
    private UploadService uploadService;

    @PostMapping("/upload")
    @ResponseBody
    public OSSResult upload(@RequestParam MultipartFile file) {
        return uploadService.upload(file);
    }

    @GetMapping("/download")
    @ResponseBody
    public OSSResult download(@RequestParam String fileName,
                              @RequestParam String downloadPath,
                              @RequestParam String downloadFileName) {
        return uploadService.download(fileName, downloadPath, downloadFileName);
    }

    @DeleteMapping("/delete")
    @ResponseBody
    public OSSResult delete(@RequestParam String fileName) {
        return uploadService.delete(fileName);
    }
}
